﻿Imports System.Data.SqlClient

Public Class frmE_Diesel

    Private Sub frmE_Diesel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        CargaDatosDespacho()

    End Sub
    Sub CargaDatosDespacho()
        dgConsumo.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim strSql As String = ""
        strSql = "Select * FROM Diesel WHERE IdDiesel=" & txtFolio.Text

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Dim Fecha As Date
        Dim FechaStr As String = ""

        Do While rdBuscar.Read()
            txtAutobus.Text = rdBuscar("NoEconomico").ToString.Trim
            Fecha = rdBuscar("Fecha")
            FechaStr = Fecha.ToString("MM/dd/yyyy")
            txtRol.Text = BuscarStrDatoCitra("SELECT NombreRuta FROM Liquidacion WHERE CONVERT(VARCHAR,Fecha,101)='" & FechaStr & "' AND IdAutobus=" & rdBuscar("IdAutobus"))
            datFecha.Value = Fecha
            dgConsumo.Rows.Add(rdBuscar("Litros"), rdBuscar("KilometrosTotales"), rdBuscar("RendimientoAnterior"), rdBuscar("RendimientoStandart"), rdBuscar("RendimientoDia"), rdBuscar("RendimientoDia") - rdBuscar("RendimientoStandart"))
            txtSubtotal.Text = rdBuscar("Subtotal")
            txtIVA.Text = rdBuscar("IVA")
            txtTotal.Text = rdBuscar("Total")
        Loop

        dgConsumo.Columns(0).DefaultCellStyle.Format = "##,##0.0"
        dgConsumo.Columns(1).DefaultCellStyle.Format = "##,##0.0"
        dgConsumo.Columns(2).DefaultCellStyle.Format = "##,##0.00"
        dgConsumo.Columns(3).DefaultCellStyle.Format = "##,##0.00"
        dgConsumo.Columns(4).DefaultCellStyle.Format = "##,##0.00"
        dgConsumo.Columns(5).DefaultCellStyle.Format = "##,##0.00"
        dgConsumo.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgConsumo.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgConsumo.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgConsumo.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgConsumo.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgConsumo.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgConsumo.Columns(0).ReadOnly = False
        dgConsumo.Columns(1).ReadOnly = False
        dgConsumo.Columns(2).ReadOnly = False
        dgConsumo.Columns(3).ReadOnly = False
        dgConsumo.Columns(4).ReadOnly = False
        dgConsumo.Columns(5).ReadOnly = False

        txtSubtotal.TextAlign = HorizontalAlignment.Right
        txtIVA.TextAlign = HorizontalAlignment.Right
        txtTotal.TextAlign = HorizontalAlignment.Right
        txtSubtotal.Text = Format(CDbl(txtSubtotal.Text), "###,###.#0")
        txtIVA.Text = Format(CDbl(txtIVA.Text), "###,###.#0")
        txtTotal.Text = Format(CDbl(txtTotal.Text), "###,###.#0")
    End Sub

    Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        Close()
    End Sub
End Class